package com.mz.mattress.admin.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mz.mattress.admin.mapper.ActivityMapper;
import com.mz.mattress.admin.service.ActivityService;
import com.mz.mattress.api.common.Result;
import com.mz.mattress.api.entity.Activity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Set;

@Slf4j
@Service
public class ActivityServiceImpl implements ActivityService {

    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public Result<IPage<Activity>> listPage(String title, Integer status, Integer pageNo, Integer pageSize) {
        Page page = new Page(pageNo, pageSize);
        Page<Activity> listPage = activityMapper.listPage(page, title, status);
        return Result.ok(listPage);
    }

    @Override
    public Result<Activity> getById(Integer id) {
        Activity activity = activityMapper.selectById(id);
        if (activity == null) {
            return Result.fail("未找到导航图片信息");
        }
        return Result.ok(activity);
    }

    @Override
    public Result add(Activity activity) {
        activityMapper.insert(activity);
        return Result.ok();
    }

    @Override
    public Result updateById(Activity activity) {
        activityMapper.updateById(activity);
        return Result.ok();
    }

    @Override
    public Result deleteByIds(Set<Integer> ids) {
        activityMapper.deleteBatchIds(ids);
        return Result.ok();
    }
}
